package com.hatricks.is.gld.work.podtoobs;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

/**
 * @packageName: com.hatricks.is.gdnwork.podtoobs
 * @className: PodToObs
 * @author: yanyuhui y568821795@outlook.com
 * @date: 2024-10-21 19:04
 * @description: pod文件上传至obs
 */
public class PodToObs {

    public static void main(String[] args) {
        // 5个参数
        String curl = "curl -k -X POST \\\n" +
                "  -F \"OSSAccessKeyId={}\" \\\n" +
                "  -F \"policy={}\" \\\n" +
                "  -F \"Signature={}\" \\\n" +
                "  -F \"success_action_status=200\" \\\n" +
                "  -F \"key={}\" \\\n" +
                "  -F \"file={}\" \\\n" +
                "  {}";
        String archiveUrl = "https://dcost-sub.glodon.com/api/service/archive/attachment/upload";
        //String archiveUrl = "https://dcost-sub-test-sprint.glodon.com/api/service/archive/attachment/upload";
        HttpRequest request = HttpUtil.createGet(archiveUrl);
        HttpResponse response = request.execute();
        JSONObject json = JSONUtil.parseObj(response.body());
        response.close();
        JSONObject data = json.getJSONObject("data");
        String fileName = "test.json";
        //String fileName = "server-basicinfo.war";
        String key = "yanyh/test/" + fileName;
        //String path = "@/usr/local/apache-tomcat/webapps/" + fileName;
        //String path = "@/opt/flink/" + fileName;
        String path = "@/" + fileName;
        //String path = "@/opt/project/logs/basicInfo/" + fileName;
        System.out.println(StrUtil.format(curl, data.getStr("access_key_id"), data.getStr("policy"), data.getStr("signature"), key, path, data.getStr("host")));
    }
}
